/ Assembly List / LJCNetCommon / NetString / GetStringWithDelimiters

Namespace - LJCNetCommon


Parameters
text - The text value.
beginDelimiter - The beginning delimiter.
startIndex - The starting index.
endDelimiter - The ending delimiter.

Returns

The text including the specified delimiters.

Syntax

C#
public static String GetStringWithDelimiters(String text, String beginDelimiter, Int32& startIndex, String endDelimiter = null)

Get the string including the specified delimiters.

Example

C#
using LJCNetCommon;

// Get the string including the specified delimiters.
private static void GetStringWithDelimiters()
{
    var source = "<summary>This is some text.</summary>";
    var startIndex = 0;
    var beginDelimiter = "<summary>";
    var endDelimiter = "</summary>";
    var text = NetString.GetStringWithDelimiters(source, beginDelimiter
        , ref startIndex, endDelimiter);
    // text = "<summary>This is some text.</summary>";
    // startIndex = -1;

    // Get text that has the same begin and end delimiter.
    // The endDelimiter is not specified or null.
    source = "|This is some text.|";
    startIndex = 0;
    beginDelimiter = "|";
    text = NetString.GetStringWithDelimiters(source, beginDelimiter
        , ref startIndex);
    // text = "|This is some text.|";
    // startIndex = -1;

    // Get text that has no end delimiter.
    source = "|This is some text.";
    startIndex = 0;
    beginDelimiter = "|";
    text = NetString.GetStringWithDelimiters(source, beginDelimiter
        , ref startIndex, "#NoDelimiter");
    // text = "|This is some text.";
    // startIndex = -1;

    // Get delimited text where the delimiters occur multiple times.
    source = "|This is some text.| |and some more here.|";
    startIndex = 0;
    beginDelimiter = "|";
    while (startIndex > -1)
    {
        text = NetString.GetStringWithDelimiters(source, beginDelimiter
            , ref startIndex);
        // First time: text = "|This is some text.|";
        // startIndex = 20;
        // Second time: text = "|and some more here.|";
        // startIndex = -1
    }
}

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.